package pailiewu.util;


import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.ArrayList;

public class Sort {
	//private static String sort3File = "e:/sort3.TXT";

	private int[] count3List;
	
	private ArrayList<String> sort3List;
	
	private int max;
	
	private String maxLine;
	
	public String getMaxLine() {
		return maxLine;
	}

	public String getMinLine() {
		return minLine;
	}
	private String minLine;
	
	public Sort(Count3 count3) throws Exception{
		
		this.count3List=count3.getCount3List();
		max=getMaxCount();
		sort3List = new ArrayList<String>();
		for (int i=0;i<max+1;i++){
			String tmp=i+"  :  ";
			sort3List.add(tmp);
		}
	}
	
	public int getMaxCount(){
		int max=0;
		for (int i=0;i<1000;i++){
			int tmp=count3List[i];
			if (tmp>max){
				max=tmp;
			}
		}
		return max;
	}
	public void sort(String sortStr) throws Exception{
		for (int i=0;i<1000;i++){
			int tmp=count3List[i];
			String a=sort3List.get(tmp);
			a=a+Count3.getIndex(i)+" ";
			sort3List.set(tmp,a);
		}
		minLine=sort3List.get(0);
		maxLine=sort3List.get(max);
		writeSort3(sortStr);
	}
	public void writeSort3(String sortStr) throws Exception {
		FileWriter fw = new FileWriter(sortStr);
		BufferedWriter bw = new BufferedWriter(fw);
		for (int i = 0; i < max+1; i++) {

			String line = sort3List.get(i);
			
			System.out.println(line);
			bw.write(line);
			bw.newLine();
		}
		bw.close();
	}
}

